package com.dp.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dp.pojo.UserOrderDetail;
import com.dp.service.impl3.BaseImpl;
import com.dp.vo.TServiceInfo;


@Service
@Transactional
public class UserorderServiceImpl extends BaseImpl{

	/*@SuppressWarnings("unchecked")
	public List<UserOrderDetail> findUserOrder (UserOrderDetail userOrderDetail){
		
		String hql = "SELECT new com.dp.pojo.UserOrderDetail(tsi.servicename, tuo.serviceCode,"+
			"tsi.price, tuo.phonenum, tuo.ordertime, tuo.ordertype, ta.areaname, tac.contentName, tuo.canceltime) " +
				" FROM TUserOrder tuo,TAuditcontents tac,TAreainfo ta, " +
				"TServiceInfo tsi WHERE tuo.contentid = tac.contentid AND tuo.areaid = ta.areaid " +
				"AND tuo.serviceCode = tsi.serviceCode ";
		if(userOrderDetail !=null){
			if (userOrderDetail.getPhonenum() !=null && !"".equals(userOrderDetail.getPhonenum())){
				hql+=" AND tuo.phonenum like '%"+userOrderDetail.getPhonenum()+"%'";
			}
			if (userOrderDetail.getServiceCode() !=null && !"".equals(userOrderDetail.getServiceCode())){
				hql+=" AND tuo.serviceCode ='"+userOrderDetail.getServiceCode()+"'";
			}
			if (userOrderDetail.getOrdertype() !=null && !"".equals(userOrderDetail.getOrdertype())){
				hql+=" AND tuo.ordertype ='"+userOrderDetail.getOrdertype()+"'";
			}
			if (userOrderDetail.getStartDate() !=null && !"".equals(userOrderDetail.getStartDate()) && userOrderDetail.getEndDate() !=null && !"".equals(userOrderDetail.getEndDate())){
				hql+=" AND tuo.ordertime BETWEEN '"+userOrderDetail.getStartDate()+"' and '"+userOrderDetail.getEndDate()+"'";
			}
		}
		return getQueryList(hql); 
 	}
	*/
	
	@SuppressWarnings("unchecked")
	public Long findUserOrderCount (UserOrderDetail userOrderDetail){
		
		String hql = "SELECT count(tuo) " +
				" FROM TUserOrder tuo,TAuditcontents tac," +
				"TServiceInfo tsi WHERE tuo.contentid = tac.contentid " +
				"AND tuo.serviceCode = tsi.serviceCode ";
		if(userOrderDetail !=null){
			if (userOrderDetail.getPhonenum() !=null && !"".equals(userOrderDetail.getPhonenum())){
				hql+=" AND tuo.phonenum like '%"+userOrderDetail.getPhonenum()+"%'";
			}
			if (userOrderDetail.getServiceCode() !=null && !"".equals(userOrderDetail.getServiceCode())){
				hql+=" AND tuo.serviceCode ='"+userOrderDetail.getServiceCode()+"'";
			}
			if (userOrderDetail.getOrdertype() !=null && !"".equals(userOrderDetail.getOrdertype())){
				hql+=" AND tuo.ordertype ='"+userOrderDetail.getOrdertype()+"'";
			}
			if (userOrderDetail.getStartDate() !=null && !"".equals(userOrderDetail.getStartDate()) && userOrderDetail.getEndDate() !=null && !"".equals(userOrderDetail.getEndDate())){
				hql+=" AND tuo.ordertime BETWEEN '"+userOrderDetail.getStartDate()+"' and '"+userOrderDetail.getEndDate()+"'";
			}
		}
		Object obj = getSingleResult(hql);
		if(obj ==null ){
			return Long.valueOf(0+"");
		}else{
			return (Long) obj;
		}
 	}
	
	@SuppressWarnings("unchecked")
	public List<UserOrderDetail> findUserOrder (UserOrderDetail userOrderDetail,int firstrow, int maxrow){
		
		String hql = "SELECT new com.dp.pojo.UserOrderDetail(tsi.servicename, tuo.serviceCode,"+
			"tsi.price, tuo.phonenum, tuo.ordertime, tuo.ordertype, ta.areaname, tac.contentName, tuo.canceltime) " +
				" FROM TUserOrder tuo,TAuditcontents tac,TAreainfo ta, " +
				"TServiceInfo tsi WHERE tuo.contentid = tac.contentid AND tuo.areaid = ta.areaid " +
				"AND tuo.serviceCode = tsi.serviceCode ";
		if(userOrderDetail !=null){
			if (userOrderDetail.getPhonenum() !=null && !"".equals(userOrderDetail.getPhonenum())){
				hql+=" AND tuo.phonenum like '%"+userOrderDetail.getPhonenum()+"%'";
			}
			if (userOrderDetail.getServiceCode() !=null && !"".equals(userOrderDetail.getServiceCode())){
				hql+=" AND tuo.serviceCode ='"+userOrderDetail.getServiceCode()+"'";
			}
			if (userOrderDetail.getOrdertype() !=null && !"".equals(userOrderDetail.getOrdertype())){
				hql+=" AND tuo.ordertype ='"+userOrderDetail.getOrdertype()+"'";
			}
			if (userOrderDetail.getStartDate() !=null && !"".equals(userOrderDetail.getStartDate()) && userOrderDetail.getEndDate() !=null && !"".equals(userOrderDetail.getEndDate())){
				hql+=" AND tuo.ordertime BETWEEN '"+userOrderDetail.getStartDate()+"' and '"+userOrderDetail.getEndDate()+"'";
			}
		}
		return getQueryList(hql,firstrow,maxrow); 
 	}

	public List<TServiceInfo> getAllService(Class<TServiceInfo> class1) {
		return super.getAll(class1);
	}
	
	
}
